﻿<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>配置管理平台</title>
    <link href="x-admin/css/font.css" rel="stylesheet" />
    <link href="x-admin/css/xadmin.css" rel="stylesheet" />
    <script src="lib/cookie/cookie.js"></script>
    <script src="lib/Base64/base64.min.js"></script>
    <script src="lib/signalr/signalr.js"></script>
    <script src="lib/signalr/menutree.js"></script>
</head>
<body>

    <div class="layui-layout layui-layout-admin">
        <div class="layui-header">
            <div class="layui-logo layui-hide-xs layui-bg-black" style="text-align:left">
                <img src="x-admin/images/ldtlogo.png" style="padding-top:10px;margin-left:10px" />
            </div>
            <div class="layui-logo layui-hide-xs layui-bg-black" style="width:300px;">配置管理平台</div>
            <ul class="layui-nav layui-layout-right">
                <li class="layui-nav-item">
                    <a href="javascript:;" onclick="editXpath()">xpath修改</a>
                </li>

                <li class="layui-nav-item layui-hide layui-show-md-inline-block">
                    <a href="javascript:;">
                        <i class="layui-icon layui-icon-template"></i>
                        <span id="versionspan"></span>
                    </a>
                    <dl class="layui-nav-child" id="versiondl"></dl>
                </li>

                <li class="layui-nav-item layui-hide layui-show-md-inline-block">
                    <a href="javascript:;">
                        <img src="x-admin/images/5db11ff4gw1e77d3nqrv8j203b03cweg.jpg" class="layui-nav-img">
                        <span id="username">test</span>
                    </a>
                    <dl class="layui-nav-child">
                        <dd><a href="">用户信息</a></dd>
                        <dd><a href="">配置</a></dd>
                        <dd><a href="javascript:;" onclick="loginout()">退出</a></dd>
                    </dl>
                </li>

                <li class="layui-nav-item" lay-header-event="menuRight" lay-unselect>
                    <a href="javascript:;">
                        <i class="layui-icon layui-icon-more-vertical"></i>
                    </a>
                </li>
            </ul>
        </div>
        <!--左侧菜单栏-->
        <div class="layui-side layui-bg-black" style="width:300px;">
            <div class="layui-side-scroll" style="width:320px;">
                <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
                <ul class="layui-nav layui-nav-tree" style="width:300px;" lay-filter="test" id="menus">
                </ul>
                <!--<div id="menuNav" lay-filter="menuNav"></div>-->
            </div>
        </div>
        <!--主要内容区域-->
        <div class="layui-body page-content" style="left:300px;">
            <!-- 内容主体区域 -->
            <div class="layui-tab tab" lay-filter="tabPage" lay-allowClose="true">
                <ul class="layui-tab-title">
                    <li class="home"><i class="layui-icon">&#xe68e;</i>我的桌面</li>
                </ul>
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show">
                        <iframe src='welcome.html' frameborder="0" scrolling="yes" class="x-iframe"></iframe>
                    </div>
                </div>
            </div>
            
        </div>

        <div class="layui-footer">
            <!-- 底部固定区域 -->
            <div class="copyright" style="text-align:center;font-size:12px">Copyright ©2021 平台开发部 v1.0 All Rights Reserved</div>
        </div>
    </div>
    <script src="lib/layui/layui.js"></script>
    <script>
        function removeCookie(name) {
            setCookie(name, 1, -1); //-1就是告诉系统已经过期，系统就会立刻去删除cookie
        };
        var user = getCookie("userinfo");
        (function () {
            //typeof(reValue) == “undefined”
            if (user == null || user=='') {
                layer.msg("未获取到用户信息");
                location.href = 'login.html';
                //layer.msg("未获取到用户信息", function () {
                //    location.href = 'login.html';
                //});
            }
        })(layui.jquery);
        //退出
        function loginout() {
            //设置过期时间；
            removeCookie("userinfo");
            removeCookie("version");
            location.href = "login.html";
        }

        //进行将请求地址缓存下来
        function gethosttingadr() {
            //删除某个键值对
            localStorage.removeItem('hosttingaddr');
            //获取配置内容
            layui.jquery.ajax({
                url: "../jsconfig.json",
                async: false,
                type: "GET",
                dataType: "json",
                success: function (json) {
                    // 写入数据
                    localStorage.setItem('hosttingaddr', json.appsetting.hosttingaddr);
                }
            });
            var addr = localStorage.getItem('hosttingaddr');
            return addr;
        }
        //获取配置地址
        var hosttingaddrtemp = gethosttingadr();

        //dom加载完毕；
        layui.$(function () {
            var userinfo = JSON.parse(window.decodeURIComponent(escape(atob(user))));
            layui.$("#username").text(userinfo.Name);

            layui.$("#versiondl").empty();
            layui.$.ajax({
                type: 'get',
                url: gethosttingadr() + '/api/UserAuthority/getversionbyusername?userName=' + userinfo.Name,
                async: false,
                cache: false,
                success: function (re) {
                    if (re.code == 0) {
                        for (var i = 0; i < re.data.length; i++) {
                            layui.$("#versiondl").append("<dd><a href='javascript:;' onclick=\"showVersion('" + re.data[i].id + "')\">" + re.data[i].name + "</a></dd>");
                        }
                        layui.form.render();
                    }
                }
            });
            var versionCookie = getCookie("version");
            if (versionCookie == null || versionCookie=="") {
                showVersion("3950678987046510592");
            }
            else {
                var version = JSON.parse(window.decodeURIComponent(escape(atob(versionCookie))));
                if (version.Id != null && version.Id != "") {
                    showVersion(version.Id);
                }
            }
        });

        function showVersion(id) {
            layui.$.ajax({
                type: 'get',
                url: gethosttingadr() + '/api/UserAuthority/getversionInfo?id=' + id,
                async: false,
                cache: false,
                success: function (da) {
                    removeCookie("version");
                    setCookie('version', da, 1);
                    var version = JSON.parse(window.decodeURIComponent(escape(atob(da))));
                    layui.$("#versionspan").text(version.Name);
                }
            })
        }

        //JS
        layui.use(['element', 'layer', 'util'], function () {
            var element = layui.element
                , layer = layui.layer
                , util = layui.util;
                //, $ = layui.$
            
            //加载左侧菜单
            layui.jquery.ajax({
                url: hosttingaddrtemp + "/api/main/getmenus",
                headers: {
                    "token": user
                },
                method: 'GET',
                cache: false,
                success: function (res) {
                    if (res.length > 0) {
                        loadMenu(res);
                        layui.element.init();
                    } else {
                        layer.msg("未获取到菜单权限", function () {
                            layui.element.init();
                        });
                    }
                    
                }
            });
        });



        function editXpath() {
            layer.open({
                type: 2,
                title: 'xpath修改',
                maxmin: true,
                shadeClose: false, //点击遮罩关闭层
                area: ['600px', '350px'],
                content: 'editxpath.html'// iframe链接地址
            });
        }


        //添加选项卡
        function addTabContent(name,code, url) {
            if (layui.jquery(".layui-tab-title li[lay-id='" + code + "']").length > 0) {
                //选项卡已经存在
                layui.element.tabChange('tabPage', code);
            } else {
                //动态控制iframe高度
                var tabheight = layui.jquery(window).height() - 95;
                //contentTxt = '<iframe src="' + url + '" scrolling="no" width="100%" height="' + (tabheight) + 'PX"></iframe>';
                contentTxt = ' <div class="layui-tab-item layui-show"><iframe src="' + url + '" frameborder="0" scrolling="yes" width="100%" height="100%"></iframe></div>';
                //新增一个Tab项
                layui.element.tabAdd('tabPage', {
                    title: name,
                    content: contentTxt,
                    id: code
                })
                //切换刷新
                layui.element.tabChange('tabPage', code)
            }
        }
    </script>
</body>
</html>